<template>
    <div class="chat_container">
        <div class="tabs">
            <div v-for="(item, index) in navList" :key="index" @click="navClick(item)"
                :class="navIndex == item.label ? 'tabs_items_active' : 'tabs_items'">
                {{ item.label }}
            </div>
        </div>
        <div class="chat_contents" v-if="tabs" v-loading="oneloading">
            <div class="zanwu" v-if="onelist.length == 0">暂无数据</div>
            <div class="chat_contents_items" v-for="(item, index) in onelist" :key="index" @click="itemsClick(item)">
                <img class="chat_contents_items_img" :src="item.titleImage" alt="">
                <div class="chat_contents_title">
                    {{ item.title }}
                </div>
                <div class="chat_contents_bottom">
                    <img src="@/assets/eye.png" alt="">
                    <div class="chat_contents_nickName">{{ item.hits }}</div>
                    <div class="chat_contents_date">{{ item.createTime }}</div>
                </div>
            </div>
            <div class="xiala" v-if="oneTotal > 12 && onequeryParams.pageNum * onequeryParams.pageSize < oneTotal">
                <img src="@/assets/下拉@2x.png" alt="" @click="pageClick()">
            </div>
        </div>
        <div class="chat_content" v-if="!tabs" v-loading="loading">
            <div class="headers">
                <div class="headers_left">
                    <video controls :src="activeDatas.videoUrl" v-if="activeDatas.video" ref="videoref"></video>
                    <img :src="activeDatas.titleImageUrl" alt="" v-else>
                    </img>
                </div>
                <div class="header_right">
                    <div class="header">{{ activeDatas.title }}</div>
                    <div class="ms">
                        <div class="ms_items">
                            主讲：{{ activeDatas.teacher }}
                        </div>
                        <div class="ms_items">
                            人气：{{ activeDatas.hits }}
                        </div>
                        <div class="ms_items">
                            类别：{{ activeDatas.type }}
                        </div>
                        <div class="ms_items">
                            发布：{{ activeDatas.createTime }}
                        </div>
                        <div class="ms_items ms_itemss">
                            要点：{{ activeDatas.point }}
                        </div>

                    </div>
                    <div class="xuxi">
                        <div class="xuxi_button" @click="xuexi">
                            <img src="@/assets/播放 (3) 拷贝@2x.png" alt="">
                            立即学习
                        </div>
                    </div>
                </div>
            </div>
            <div class="tops">
                <div class="zi">科普介绍</div>
            </div>
            <div class="cons" v-html="activeDatas.content"></div>
            <div class="tops">
                <div class="zi">相关科普</div>
            </div>

            <div class="chat_contents_itemss" v-for="(item, index) in relatedList" :key="index">
                <img class="chat_contents_items_img" :src="item.titleImage" alt="">
                <div class="chat_contents_title">
                    <div class="recommend" v-if="item.recommend == 1">
                        推荐
                    </div>
                    <div class="recommend_title">
                        {{ item.title }}
                    </div>
                </div>
                <div class="chat_contents_bottom">
                    <img src="@/assets/eye.png" alt="">
                    <div class="chat_contents_nickName">{{ item.hits }}</div>
                    <div class="chat_contents_date">{{ item.createTime }}</div>
                </div>
            </div>
        </div>

    </div>
</template>

<script setup lang="ts">
import { getPopularize, listPopularize, } from '@/api/index'
const navList = ref([
    { label: '全部' },
    { label: '自然科学', },
    { label: '天文知识', },
    { label: '航天科技', },
    { label: '信息通信', },
    { label: '人工智能', },
    { label: '生物工程', },
    { label: '神奇化学', },
    { label: '物理探秘', },
    { label: '生命健康', },
])
const navIndex = ref('全部')
const videoref = ref()

const onequeryParams = ref({
    pageNum: 1, pageSize: 12, type: ''
})
const activeDatas = ref<any>({})
const tabs = ref(true)
const relatedList = ref([])

const oneloading = ref(false)
const onelist = ref([])
const oneTotal = ref(0)
const loading = ref(false)


const navClick = (item) => {
    tabs.value = true
    navIndex.value = item.label
    if (item.label == '全部') {
        onequeryParams.value.type = ''
    } else {
        onequeryParams.value.type = item.label
    }
    activeDatas.value = {}
    onequeryParams.value.pageNum = 1
    getOneList()
}

const xuexi = () => {
    if (videoref.value) {
        videoref.value.play()
    }
}

// 右侧点击
const itemsClick = async (item) => {
    tabs.value = false
    loading.value = true
    const res = await getPopularize(item.id)
    res.data.titleImageUrl = import.meta.env.VITE_APP_PIC_URL + '/' + res.data.titleImage
    res.data.videoUrl = import.meta.env.VITE_APP_PIC_URL + '/' + res.data.video
    res.data.createTime = res.data.createTime.split(' ')[0]
    activeDatas.value = res.data

    // 获取相关科普
    const response = await listPopularize({ pageNum: 1, pageSize: 8, type: res.data.type })
    response.rows.forEach(element => {
        element.titleImage = import.meta.env.VITE_APP_PIC_URL + '/' + element.titleImage
    });
    relatedList.value = response.rows
    loading.value = false
}




// 一页十二条 科普列表
const getOneList = async () => {
    oneloading.value = true
    const res = await listPopularize(onequeryParams.value)
    res.rows.forEach(element => {
        element.createTime = element.createTime.split(' ')[0].replace(/-/g, ".")
        element.titleImage = import.meta.env.VITE_APP_PIC_URL + '/' + element.titleImage

    });
    oneTotal.value = res.total
    onelist.value = res.rows
    oneloading.value = false
}

// 首页分页
const pageClick = () => {
    onequeryParams.value.pageNum++
    getOneList()
}


onMounted(async () => {
    getOneList()
});

</script>

<style scoped lang="scss">
:deep(.el-textarea__inner) {
    min-height: 160px !important;
}

.chat_container {
    margin: 0;
    padding: 0;
    width: 100%;
    background-color: #f5f7fa;
    opacity: 0.8;
    display: flex;
    align-items: center;
    justify-content: center;
    display: flex;
    flex-wrap: wrap;
    align-content: center;
    overflow: auto;
    box-sizing: content-box;
    padding-top: 100px;



    .tabs {
        width: 1400px;
        margin-bottom: 20px;
        margin-left: 20px;
        margin-top: 20px;
        display: flex;
        align-items: center;

        .tabs_items {
            margin-right: 30px;
            color: #A0A0A0;
            font-size: 16px;
            cursor: pointer;
        }

        .tabs_items_active {
            margin-right: 30px;
            color: #000000;
            font-size: 18px;
            cursor: pointer;
        }
    }

    .chat_contents {
        width: 1400px;
        background: #FFFFFF;
        box-shadow: 0px 2px 7px 0px rgba(0, 0, 0, 0.09);
        border-radius: 20px;
        box-sizing: border-box;
        padding: 40px 50px;
        display: flex;
        align-items: flex-start;
        flex-wrap: wrap;
        justify-content: flex-start;
        overflow: auto;

        .zanwu {
            width: 100%;
            line-height: 981px;
            text-align: center;
            color: #A0A0A0;
        }

        .xiala {
            width: 100%;
            display: flex;
            align-items: center;
            justify-content: center;

            img {
                width: 28px;
                height: 28px;
                cursor: pointer;
            }
        }

        .chat_contents_items {
            width: calc(100% / 4);
            cursor: pointer;
            display: flex;
            flex-wrap: wrap;
            justify-content: center;

            .chat_contents_items_img {
                width: 284px;
                height: 194px;
                border-radius: 10px;
            }

            .chat_contents_title {
                font-family: Adobe Heiti Std;
                font-weight: normal;
                font-size: 14px;
                color: #000000;
                width: 284px;
                display: -webkit-box;
                -webkit-box-orient: vertical;
                -webkit-line-clamp: 2;
                overflow: hidden;
                text-overflow: ellipsis;
                margin-top: 20px;
                height: 40px;
            }

            .chat_contents_bottom {
                display: flex;
                align-items: center;
                width: 284px;
                justify-content: space-between;
                margin-top: 10px;
                margin-bottom: 30px;

                img {
                    width: 12px;
                    height: 8px;
                    border-radius: 50%;
                }

                .chat_contents_nickName {
                    font-size: 14px;
                    color: #959595;
                    flex: 1;
                    white-space: nowrap;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    padding: 0 10px;
                }

                .chat_contents_date {
                    font-size: 12px;
                    color: #959595;
                }
            }

        }
    }

    .chat_content {
        width: 1400px;
        background: #FFFFFF;
        box-shadow: 0px 2px 7px 0px rgba(0, 0, 0, 0.09);
        border-radius: 20px;
        box-sizing: border-box;
        padding: 48px 60px;
        display: flex;
        align-items: center;
        flex-wrap: wrap;
        align-content: flex-start;
        overflow: auto;

        .headers {
            display: flex;
            align-items: center;
            justify-content: space-between;
            height: 388.7px;
            width: 100%;

            .headers_left {
                video {
                    width: 543.8px;
                    height: 388.7px;
                    border-radius: 10px;
                }

                img {
                    width: 543.8px;
                    height: 388.7px;
                    border-radius: 10px;
                }
            }

            .header_right {
                width: calc(100% - 543.8px);
                box-sizing: border-box;
                padding-left: 40px;
                height: 388.7px;

                .header {
                    font-family: Microsoft YaHei;
                    font-weight: 400;
                    font-size: 30px;
                    color: #000000;
                    display: -webkit-box;
                    -webkit-box-orient: vertical;
                    -webkit-line-clamp: 2;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    height: 80px;
                    margin-bottom: 30px;
                }

                .ms {
                    width: 100%;
                    display: flex;
                    align-items: center;
                    justify-content: space-between;
                    flex-wrap: wrap;

                    .ms_items {
                        width: 50%;
                        font-family: Microsoft YaHei;
                        font-weight: 400;
                        font-size: 18px;
                        color: #848484;
                        text-align: left;
                        margin-bottom: 30px;
                    }

                    .ms_itemss {
                        width: 100%;
                    }
                }

                .xuxi {
                    width: 100%;
                    display: flex;
                    align-items: center;
                    justify-content: flex-start;
                    margin-top: 60px;

                    .xuxi_button {
                        width: 189px;
                        height: 55px;
                        background: #4095E5;
                        border-radius: 10px;
                        font-family: Adobe Heiti Std;
                        font-weight: normal;
                        font-size: 24px;
                        color: #FFFFFF;
                        text-align: center;
                        line-height: 55px;
                        display: flex;
                        align-items: center;
                        justify-content: center;
                        cursor: pointer;

                        img {
                            width: 25px;
                            height: 25px;
                            margin-right: 10px;
                            margin-top: 3px;
                        }

                    }
                }
            }

        }

        .tops {
            margin-top: 60px;
            width: 100%;
            height: 1px;
            background-color: #9F9F9F;
            position: relative;

            .zi {
                position: absolute;
                font-family: Microsoft YaHei;
                font-weight: 400;
                font-size: 24px;
                color: #000000;
                width: 120px;
                left: 25px;
                top: -17px;
                background-color: #FFFFFF;
                text-align: center;
            }
        }

        .cons {
            width: 100%;
        }

        .chat_contents_itemss {
            width: calc(100% / 4);
            cursor: pointer;
            display: flex;
            flex-wrap: wrap;
            justify-content: center;
            margin-top: 30px;

            .chat_contents_items_img {
                width: 270px;
                height: 182px;
                border-radius: 10px;
            }

            .chat_contents_title {
                font-family: Adobe Heiti Std;
                font-weight: normal;
                font-size: 14px;
                color: #000000;
                width: 270px;
                margin-top: 20px;
                height: 40px;
                display: flex;
                align-items: baseline;

                .recommend {
                    display: inline-block;
                    width: 33px;
                    height: 16px;
                    background-color: rgb(249, 0, 0);
                    color: #fff;
                    font-size: 10px;
                    text-align: center;
                    line-height: 16px;
                    letter-spacing: 2px;
                    border-top-right-radius: 15px;
                    border-bottom-right-radius: 15px;
                    margin-right: 10px;
                }

                .recommend_title {
                    flex: 1;
                    display: -webkit-box;
                    -webkit-box-orient: vertical;
                    -webkit-line-clamp: 2;
                    overflow: hidden;
                    text-overflow: ellipsis;
                }
            }

            .chat_contents_bottom {
                display: flex;
                align-items: center;
                width: 270px;
                justify-content: space-between;
                margin-top: 10px;

                img {
                    width: 12px;
                    height: 8px;
                    border-radius: 50%;
                }

                .chat_contents_nickName {
                    font-size: 14px;
                    color: #959595;
                    flex: 1;
                    white-space: nowrap;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    padding: 0 10px;
                }

                .chat_contents_date {
                    font-size: 12px;
                    color: #959595;
                }
            }

        }
    }
}
</style>